import com.itheima.UserService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
 * ClassName: test_ai
 * Package: PACKAGE_NAME
 * Description:
 *
 * @Author liu
 * @Create 2025/5/13 21:54
 * @ Version 1.0
 */
public class test_ai {
    private UserService userService;

    @BeforeEach
    public void setUp() {
        userService = new UserService();
    }

    /**
     * TC001: 输入 null 应抛出 IllegalArgumentException
     */
    @Test
    public void testGetAgeWithNullIdCard_shouldThrowException() {
        Exception exception = assertThrows(IllegalArgumentException.class, () -> {
            userService.getAge(null);
        });

        assertEquals("无效的身份证号码", exception.getMessage());
    }

    /**
     * TC002: 输入空字符串应抛出 IllegalArgumentException
     */
    @Test
    public void testGetAgeWithEmptyIdCard_shouldThrowException() {
        Exception exception = assertThrows(IllegalArgumentException.class, () -> {
            userService.getAge("");
        });

        assertEquals("无效的身份证号码", exception.getMessage());
    }

    /**
     * TC003: 输入长度不足的身份证号应抛出 IllegalArgumentException
     */
    @Test
    public void testGetAgeWithInvalidLengthIdCard_shouldThrowException() {
        String idCard = "1234567890123"; // 13位
        Exception exception = assertThrows(IllegalArgumentException.class, () -> {
            userService.getAge(idCard);
        });

        assertEquals("无效的身份证号码", exception.getMessage());
    }



}
